package org.noworks.purdue.mapeditor;

import java.awt.BasicStroke;
import java.awt.Color;
import java.awt.Graphics;
import java.awt.Graphics2D;
import java.awt.Point;

public class Location {

	private static final int SIZE = 20;
	private final static float dash1[] = { 3.0f };
	private final static BasicStroke dashed = new BasicStroke(1.0f,
			BasicStroke.CAP_BUTT, BasicStroke.JOIN_MITER, 3.0f, dash1, 0.0f);
	private Point point;
	private String name;
	private long id;

	private static long ID = 0;

	private static long generateId() {
		ID++;
		return ID - 1;
	}

	public void draw(Graphics g) {
		g.setColor(Color.RED);
		g.fillOval((int) point.getX() - SIZE / 2,
				(int) point.getY() - SIZE / 2, SIZE, SIZE);
	}

	public void drawSelect(Graphics g) {
		Graphics2D g2 = (Graphics2D) g;
		g2.setColor(Color.BLACK);
		g2.setStroke(dashed);
		g.drawRect((int) point.getX() - SIZE / 2,
				(int) point.getY() - SIZE / 2, SIZE, SIZE);
	}

	/**
	 * Return true if this point is inside of this location.
	 */
	public boolean isThisYou(Point p) {
		int x = (int) point.getX();
		int y = (int) point.getY();
		int px = (int) p.getX();
		int py = (int) p.getY();
		int radius = SIZE / 2;
		return px > x - radius && px < x + radius && py > y - radius
				&& py < y + radius;
	}

	public Location(Point point, String name, long id) {
		super();
		this.point = point;
		this.name = name;
		this.id = id;
		if (ID < id)
			ID = id;
	}

	public Location(Point point, long id) {
		super();
		this.point = point;
		this.id = id;
		if (ID < id)
			ID = id;
	}

	public Location(Point point, String name) {
		super();
		this.point = point;
		this.name = name;
		id = generateId();
	}

	public Location(Point point) {
		super();
		this.point = point;
		name = "";
		id = generateId();
	}
	
	public void showInfo() {
		
	}

	public Point getPoint() {
		return point;
	}

	public void setPoint(Point point) {
		this.point = point;
	}

	public String getName() {
		return name;
	}

	public void setName(String name) {
		this.name = name;
	}

	public long getId() {
		return id;
	}

	public void setId(long id) {
		this.id = id;
	}
}
